package com.allwees.bs.c.module.security;

import com.alibaba.fastjson.JSON;
import com.allwees.bs.core.modelbase.vo.R;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class AjaxAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
        ResponsePrinter.write(response, JSON.toJSONString(R.error(e.getMessage())));
    }
}
